/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.contribute.common.pojo;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author debian
 */
@XmlRootElement
public class Temperature implements Serializable{
    
    int id, roomId;
    double tempValue, humValue;
    Date time;
    
    public Temperature(int id, int roomId, double tempValue, double humValue, Date time) {
        this.id = id;
        this.roomId = roomId;
        this.tempValue = tempValue;
        this.humValue = humValue;
        this.time = time;
    }

    public Temperature() {
    }
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public double getTempValue() {
        return tempValue;
    }

    public void setTempValue(double tempValue) {
        this.tempValue = tempValue;
    }

    public double getHumValue() {
        return humValue;
    }

    public void setHumValue(double humValue) {
        this.humValue = humValue;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public void print() {
        System.out.println("----------------------------");
        System.out.println("Id: " + id);
        System.out.println("TempValue: "+tempValue);
        System.out.println("HumValue: "+humValue);
        System.out.println("Time: "+time);
        System.out.println("RoomId: "+roomId);
    }
    
    public static Temperature averageFromList(List<Temperature> pList)
    {
        if(pList.size() > 0)
        {
            Double totalHum = 0.0, totalTemp = 0.0;
             for(Temperature temp: pList)
             {
                 totalHum = totalHum + temp.getHumValue();
                 totalTemp = totalTemp + temp.getTempValue();
             }
             return new Temperature(1,pList.get(0).getRoomId(),totalTemp/pList.size(),totalHum/pList.size(), pList.get(0).getTime());
        }
        else
            return null;
    }

    @Override
    public String toString() {
        return "Temperature{" + "id=" + id + ", roomId=" + roomId + ", tempValue=" + tempValue + ", humValue=" + humValue + ", time=" + time + '}';
    }
}

